package com.personal.ifanya.presentation.interceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.stereotype.Repository;
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;
 
import com.personal.ifanya.presentation.model.SessionBox;

/**
 * @author tangb
 *
 */
@Repository
public class SessionInterceptor extends HandlerInterceptorAdapter {


	/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * org.springframework.web.servlet.handler.HandlerInterceptorAdapter#preHandle
	 * (javax.servlet.http.HttpServletRequest,
	 * javax.servlet.http.HttpServletResponse, java.lang.Object)
	 */
	@SuppressWarnings({ "rawtypes", "unchecked" })
	@Override
	public boolean preHandle(HttpServletRequest request,
			HttpServletResponse response, Object handler) throws Exception {


		SessionBox sessionBox = (SessionBox) request.getSession().getAttribute("sessionBox"); 
		
	    if(sessionBox==null)
	    {
	    	sessionBox = new SessionBox(); 
	    	request.getSession().setAttribute("sessionBox", sessionBox);
	    }
	    
	    
		return super.preHandle(request, response, handler);
	}

	
}
